package jdbc;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-07-31 下午5:06
 */
public class CustomerDaoTest extends AbstractJdbcDaoImpl {
    private static final Logger LOGGER = LoggerFactory.getLogger(CustomerDaoTest.class);
    private DaoBase<Customer> dao = new CustomerDao();

    @Test
    public void batch() {
    }

    @Test
    public void getForValue() {
    }

    @Test
    public void getForList() {
        Connection connection = null;
        try {
            connection = JdbcUtils.getConnection();
            String sql = "SELECT id, name, email, birth FROM customers WHERE id>?";
            List<Customer> customers = dao.getForList(connection, sql, 5);
            customers.forEach(x -> LOGGER.info(x.toString()));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.release(connection, null);
        }
    }

    @Test
    public void get() {
        Connection connection = null;
        try {
            connection = JdbcUtils.getConnection();
            String sql = "SELECT id, name, email, birth FROM customers WHERE id=?";
            Customer customer = dao.get(connection, sql, 4);
            LOGGER.info(customer.toString());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.release(connection, null);
        }
    }

    @Test
    public void update() {
    }
}